import { localCache } from '@/utils/cache'
import StoneRequest from './request'
import { BASE_URL, TIME_OUT } from './request/config'
import { LOGIN_TOKEN } from '@/global/constants'


const stoneRequest = new StoneRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    //这个请求拦截每一次都自动携带token
    requestSuccessFn: (config) => {
      const token = localCache.getCache(LOGIN_TOKEN)
      if(config.headers && token)
      config.headers.Authorization = 'Bearer ' + token
      return config
    }
  }
})

export default stoneRequest
